package com.cskaoyan.service;

import com.cskaoyan.bean.MarketSearchHistory;
import com.cskaoyan.bean.MarketSearchHistoryExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketSearchHistoryMapper;
import com.cskaoyan.util.StringUtil;
import com.cskaoyan.util.TransactionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class HistoryServiceImpl implements HistoryService {
    @Override
    public CommonData<MarketSearchHistory> query(Integer page, Integer limit, String sort, String order, Integer userId, String keyword) {
        MarketSearchHistoryExample example=new MarketSearchHistoryExample();
        MarketSearchHistoryExample.Criteria criteria = example.createCriteria();

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (keyword != null) {
            criteria.andKeywordLike("%"+keyword+"%");
        }

//        criteria.andDeletedEqualTo(false);

        if (!StringUtil.isEmpty(sort) && !StringUtil.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        PageHelper.startPage(page, limit);


        MarketSearchHistoryMapper marketSearchHistoryMapper = TransactionUtil.getMapper(MarketSearchHistoryMapper.class);
        PageHelper.startPage(page, limit);
        List<MarketSearchHistory> marketSearchHistories= marketSearchHistoryMapper.selectByExample(example);
        return CommonData.data(new PageInfo(marketSearchHistories));
    }
}
